package com.jintian.smart.kernel.common.expr.op.define;

import com.jintian.smart.kernel.common.expr.datameta.BaseDataMeta;
import com.jintian.smart.kernel.common.expr.datameta.Constant;
import com.jintian.smart.kernel.common.expr.op.Operator;
import com.jintian.smart.kernel.core.expr.IllegalExpressionException;

/**
 * 逻辑等于操作
 */
public class Op_EQ extends Op_Base {
    public Op_EQ() {
        super(Operator.EQ);
    }

    public Constant execute(Constant[] args) throws IllegalExpressionException {
        Object[] params = this.getParameterValues(args);
        if (params[0] == null && params[1] == null) {
            return new Constant(BaseDataMeta.DataType.DATATYPE_BOOLEAN, true);
        } else if (params[0] == null || params[1] == null) {
            return new Constant(BaseDataMeta.DataType.DATATYPE_BOOLEAN, false);
        }
        int compare = this.compare(params[0], params[1], null);
        return new Constant(BaseDataMeta.DataType.DATATYPE_BOOLEAN, compare == 0);
    }

    public Constant verify(int opPositin, BaseDataMeta[] args) throws IllegalExpressionException {
        this.checkParameterCount(opPositin, args);
        return new Constant(BaseDataMeta.DataType.DATATYPE_BOOLEAN, Boolean.FALSE);
    }
}
